package com.liu.email;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;

public class MyMimeMessageEmail {
	public static void main(String[] args) throws Exception {
		sendMimeMessageEmail();
		// 属性对象
		Properties properties = new Properties();
		// 开启debug调试 ，打印信息
		properties.setProperty("mail.debug", "true");
		// 发送服务器需要身份验证
		properties.setProperty("mail.smtp.auth", "true");
		// 发送服务器端口
		properties.setProperty("mail.smtp.port", "25");
		// 发送邮件协议名称
		properties.setProperty("mail.transport.protocol", "smtp");
		// 设置邮件服务器主机名
		properties.setProperty("mail.host", "smtp.qq.com");
		// 环境信息
		Session session = Session.getInstance(properties, new Authenticator() {
			@Override
			protected PasswordAuthentication getPasswordAuthentication() {
				// 在session中设置账户信息，Transport发送邮件时会使用
				return new PasswordAuthentication("1299616634@qq.com", "kiwjgnnajkcjhdja");
			}
		});

		// 读取本地邮件
		Message message = new MimeMessage(session, new FileInputStream(new File("C:/Users/ydxx/Desktop/demo.eml")));

		// 设置收件人地址发送邮件
		Transport.send(message, InternetAddress.parse("liubo20180827@cnsunet.com"));
	}

}
